import {Component} from '@angular/core';
import {IonicPage, NavController, NavParams, ViewController} from 'ionic-angular';
import {StorageProvider} from "@providers/storage";
import {DialogProvider} from "@providers/dialog";
import {WorkerProvider} from "@providers/interface/worker";

@IonicPage()
@Component({
  selector: 'page-rpay',
  templateUrl: 'rpay.html',
})
export class RpayPage {
  userInfo: any;
  cacheOrder: any = this.navParams.data;

  constructor(public navCtrl: NavController, public navParams: NavParams,
              private storage: StorageProvider, private worker: WorkerProvider,
              private dialog: DialogProvider, private viewCtrl: ViewController) {
    this.userInfo = this.storage.read("userInfo");
  }

  ionViewDidLoad() {
    this.dialog.hideLoading();
    console.log(JSON.stringify(this.cacheOrder));
  }

  dismiss() {
    this.viewCtrl.dismiss();
  }

  /**
   * 现金支付
   */
  payCash() {
    /*if (this.userInfo.YZMCS == 1) {
      this.dialog.showRadioOrCheckbox((data) => {
          if (!Util.isNull(data.yzm)) {
            this.dialog.showLoading();
            this.wandan(data.yzm);
          } else {
            this.dialog.showAlert("请输入验证码！");
            this.dialog.hideLoading();
            return;
          }
        }, "是否确定完工！",
        [{
          name: 'yzm',
          type: 'text',
          placeholder: '请输入验证码'
        }])
    } else {*/
    if (this.cacheOrder.serviceTypeId != '1') {
      console.log("123456");
      this.dialog.showConfirm(() => {
        this.dialog.showLoading();
        this.wandan();
      }, "是否确定完工！")
    } else {
      this.viewCtrl.dismiss(true);
    }
    // }
  }

  /**
   * 微信扫码支付
   */
  weixinPay() {
    this.navCtrl.push("WxPayQrcodePage", this.cacheOrder)
  }

  /**
   * 支付宝扫码支付
   */
  aliPay() {

  }

  wandan(yzm?) {
    this.cacheOrder.azlist = this.storage.read("azlist") ? this.storage.read("azlist") : [];
    if (yzm){
    this.cacheOrder.YZM = yzm;
    }
    this.worker.wandan(this.cacheOrder).then((message) => {
      this.dialog.hideLoading();
      // this.dialog.showAlert("完工成功！");
      this.viewCtrl.dismiss(true);
    }).catch((error) => {
      this.dialog.hideLoading();
    });
  }
}
